define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'protocol_airline/index' + location.search,
                    add_url: 'protocol_airline/add',
                    edit_url: 'protocol_airline/edit',
                    del_url: 'protocol_airline/del',
                    multi_url: 'protocol_airline/multi',
                    import_url: 'protocol_airline/import',
                    table: 'protocol_airline',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                commonSearch: true,
                searchFormVisible: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        // {field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'province', title: __('Province'), operate: 'LIKE'},
                        // {field: 'city', title: __('City'), operate: 'LIKE'},
                        // {field: 'area', title: __('Area'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'lat', title: __('Lat'), operate: 'LIKE'},
                        // {field: 'lng', title: __('Lng'), operate: 'LIKE'},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };


    if($('#c-city').val()){
        $('.city').removeClass('hide');
    }

    if($('#c-area').val()){
        $('.area').removeClass('hide');
    }

    $(document).on('change', "#c-province", function (e, first) {
        //清除SelectPage数据
        $('#c-city').selectPageClear();
        $('#c-area').selectPageClear();

        $('.city').removeClass('hide');
        $('.area').addClass('hide');
    });

    $(document).on('change', "#c-city", function (e, first) {
        $("#c-area").selectPageClear();

        $('.area').removeClass('hide');
    });

    $("#c-city").data("params", function (obj){
        return {custom: {province:$("#c-province").val()}}
    });

    $("#c-area").data("params", function (obj){
        return {custom: {province:$("#c-province").val(),city:$("#c-city").val()}}
    });

    return Controller;
});
